CC=avr-gcc
#CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega16
OBJ2HEX=avr-objcopy 
UISP=/usr/local/bin/uisp 
TARGET=blink

SRCS = ./main/main.c

# List all user directories here
UINCDIR =	./main \
		./main/inc
	

# List the user directory to look for the libraries here
ULIBDIR =

INCDIR  = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))

OBJS = $(SRCS:.c=.o)

DEFS           =
LIBS           = ./main/libJoyRtos.a

OPTIMIZE       = -O2
MCU_TARGET     = atmega16

CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -I . $(INCDIR)
LDFLAGS       = -Wl,-Map,$(PRG).map


all: $(OBJS) blink.elf blink.hex
%.obj : %.o
	$(CC) $(CFLAGS) $< -o $@

$(TARGET).elf: $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

%.hex : %.elf
	$(OBJ2HEX) -R .eeprom -O ihex $< $@
	#avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex blink.elf blink.hex

clean :
	rm -f *.hex *.obj *.o $(OBJS) blink.elf
